Don't hose if we replace a string with a string that's a supserset of the origin...
authorrobertl <robertl>
Mon, 31 Mar 2008 02:51:05 +0000 (02:51 +0000)
committerrobertl <robertl>
Mon, 31 Mar 2008 02:51:05 +0000 (02:51 +0000)
util.c

diff --git a/util.c b/util.c
index d76b7ea3b823d62f1b051fa7df00e9124d4af9b3..17807097f0093a0e9a0cdc26e81a0c7db6d8ab90 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1104,10 +1104,14 @@ char *
 gstrsub(const char *s, const char *search, const char *replace)
 {
        char *o = xstrdup(s);
-
-       while (strstr(o, search)) {
+       char *tsearch = o;
+       // The tsearch silliness here is in case we decide to replace a string
+       // with a string that's a superset of that string.  Replacing ";" 
+       // with "\\;" in the vcf writer is our problem child.
+       while ((tsearch = strstr(tsearch, search))) {
                char *oo = o;
                o = strsub(o, search, replace);
+               tsearch = tsearch + strlen(replace);
                xfree(oo);
        }